package com.emser.unc.restlet.manager;

import java.io.Serializable;
import java.util.concurrent.Callable;

import org.restlet.data.ChallengeScheme;
import org.restlet.resource.ClientResource;

import com.emser.unc.restlet.VersionResource;
import com.emser.unc.serializable.DataStoreVersion;
import com.emser.unc.serializable.SellerDTO;

public class StateTransferManager extends TransferManager implements Callable<String>{
	
	private SellerDTO seller;
	private VersionResource versionResource;
	private DataStoreVersion dataStoreVersion;

	@Override
	public void setParams(String url, String userRest, String PassRest) {
		// TODO Auto-generated method stub
		seller = new SellerDTO();
		ClientResource cr = new ClientResource(url);
		cr.setRequestEntityBuffering(true);
		cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userRest, PassRest);
		versionResource = cr.wrap(VersionResource.class);
	}

	@Override
	public void setRequest(Serializable objectDTO) {
		// TODO Auto-generated method stub
		this.seller = (SellerDTO) objectDTO;
	}

	@Override
	public Serializable getResponse() {
		// TODO Auto-generated method stub
		return dataStoreVersion;
	}

	@Override
	public String call() throws Exception {
		// TODO Auto-generated method stub
		dataStoreVersion = versionResource.getVersion(seller);
		return "Received successfully";
	}

}
